package com.web.currencypair.service;

import com.web.currencypair.entity.CurrencyPair;
import com.web.currencypair.mapper.CurrencyPairMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author wenzhuo
 * @create 2024-01-10 2024/1/10
 */

@Service
public class CurrencyPairService {

    @Resource
    private CurrencyPairMapper currencyPairMapper;

    public List<CurrencyPair> getCurrencyPairList(String currencyFrom, String currencyTo){
        return currencyPairMapper.getCurrencyPairList(currencyFrom,currencyTo);
    }

    public CurrencyPair checkCurrencyPair(String currencyFrom, String currencyTo) {

        CurrencyPair pair = null;
        List<String> currencyPairList = new ArrayList<>();
        currencyPairList.add(currencyFrom + currencyTo);
        currencyPairList.add(currencyTo + currencyFrom);

       for (String currencyPair: currencyPairList){
           pair = currencyPairMapper.getCurrencyPair(currencyPair);
           if(pair != null){
               break;
           }
       }
       return pair;
    }
}
